﻿
@{
    ViewBag.Title = "资金明细";
}
@section CSS{

}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            财务明细
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">财务管理</a></li>
            <li class="active">财务明细</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header my_search">
                        <select style="width:150px;" class="form-control" id="log_status">
                            <option value="-1">- 交易类型 -</option>
                            <option value="20">提现</option>
                            <option value="30">货款结算</option>
                            <option value="31">订单退款</option>

                        </select>
                        <select style="width:150px;" class="form-control" id="log_in_out">
                            <option value="-1">- 收支类型 -</option>
                            <option value="1">收入</option>
                            <option value="2">支出</option>
                        </select>
                        <input type="text" style="width:120px;" class="form-control pull-left" id="log_startTime" placeholder="交易日期-起">
                        <span style="line-height:30px;">至</span>
                        <input type="text" style="width:120px;" class="form-control pull-left" id="log_endTime" placeholder="交易日期-止">
                        @*<input type="text" style="width:180px;" class="form-control" id="orderNo" placeholder="订单编号">*@
                        <button type="button" class="btn btn-default " id="log_btnSearch"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                    <div class="box-body">
                        <table id="DataList1" class="table table-bordered table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th>交易日期</th>
                                    <th>交易</th>
                                    <th>收入金额(元)</th>
                                    <th>支出金额(元)</th>
                                    <th width="200">状态</th>
                                    <th>查看</th>
                                </tr>
                            </thead>
                            <tbody> </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>
        function FinanceReturnList(type) {
            u_table2.fnDestroy();
            GenerateTable2(type);
        }
        $(function () {
            //初始化表格
            GenerateTable1();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#log_btnSearch").on("click", function () {
                var classSelect = $("#classSelect").val();
                var datemin = $('#log_startTime').val();
                var datemax = $("#log_endTime").val();
                if ((datemin == null && datemax != null) || (datemin != null && datemax == null)) {
                    layer.msg('请把时间填充完整!', { icon: 1, time: 1000 });
                }
                else {
                    u_table1.fnDestroy();
                    GenerateTable1();
                }
            });

            $('#log_startTime').datepicker({
                autoclose: true
            });

            $('#log_endTime').datepicker({
                autoclose: true
            });
        });
        //结算
        function GenerateTable1() {
            u_table1 = $('#DataList1').dataTable({
                "lengthChange": false,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var datemin = $('#log_startTime').val();
                    var datemax = $("#log_endTime").val();
                    var status = $("#log_status").val();
                    var type = $("#log_in_out").val();
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                         { "name": "status", "value": status },
                        { "name": "type", "value": type }
                    );
                },
                "sAjaxSource": "/finance/FinanceLogList",
                "aoColumns": [
                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD");
                        }
                    },
                     //{ "mDataProp": 'id' },
                    //{ "mDataProp": "log_no" },
                    //{ "mDataProp": 'order_no' },
                     {
                         "mDataProp": 'trade_type', "mRender": function (data, type, full) {
                             return full.in_out == 1 ? (data == 30 ? "<span style='color:green'>货款<br/>结算订单（<a href = '/Order/GoodsOrder/" + full.order_id + "' target='_blank' title='订单详情'>" + full.order_no + "</a>）</span>" : (data == 22 ? "<span style='color:green'>拒绝提现<br/>提现流水（<a href='javascript:void(0);' onclick='admin_edit(\"提现详情\",\"/Finance/WithdrawalDetails\"," + full.relation_id + ",500,600)'  title='详情'>" + full.relation_no + "</a>）</span>" : "—")) : (data == 31 ? "<span style='color:red'>退款<br/>结算订单（<a href = '/Order/GoodsOrder/" + full.order_id + "' target='_blank' title='订单详情'>" + full.order_no + "</a>）</span>" : (data == 20 ? "<span style='color:red'>提现<br/>提现流水（<a href='javascript:void(0);' onclick='admin_edit(\"提现详情\",\"/Finance/WithdrawalDetails\"," + full.relation_id + ",500,600)'  title='详情'>" + full.relation_no + "</a>）</span>" : (data == 21 ? "<span style='color:red'>提现手续费<br/>提现流水（<a href='javascript:void(0);' onclick='admin_edit(\"提现详情\",\"/Finance/WithdrawalDetails\"," + full.relation_id + ",500,600)'  title='详情'>" + full.relation_no + "</a>）</span>" : "<span style='color:#cdcdcd'>——</span>")));
                         }
                     },
                    {
                        "mDataProp": 'in_out', "mRender": function (data, type, full) {
                            return data == 1 ? "<span style='color:green'>+" + (full.end - full.before).toFixed(2) + "</span>" : "<span style='color:#cdcdcd'>——</span>";
                        }
                    },
                    {
                        "mDataProp": 'in_out', "mRender": function (data, type, full) {
                            return data == 2 ? "<span style='color:red'>" + (full.end - full.before).toFixed(2) + "</span>" : "<span style='color:#cdcdcd'>——</span>";
                        }
                    }
                    ,{ "mDataProp": 'remark' }
                    , {
                        "mDataProp": 'id', "mRender": function (data, type, full) {
                            if (full.trade_type == 20 || full.trade_type == 21 || full.trade_type == 22) {
                                return ' <a href="javascript:void(0);" onclick="admin_edit(\'提现详情\',\'/Finance/WithdrawalDetails\',' + full.relation_id + ',500,600)"  title="详情">详情</a> ';
                            }
                            else {
                                return ' <a href="javascript:void(0);" onclick="admin_edit(\'结算详情\',\'/Finance/SettlementDetails\',' + full.relation_id + ',500,600)"  title="详情">详情</a> ';
                            }
                        }
                    }
                ]
            });
        }
        /*增加*/
        function admin_add(title, url, w, h) {
            layer_show(title, url, "", w, h);
        };

        /*编辑*/
        function admin_edit(title, url, id, w, h) {
            layer_show(title, url, id, w, h);
        };
    </script>
}
